package com.lwl.leetcode;

/**
 * @author lwl
 * @Description TODO
 * @date 2025/9/13 17:19
 */
public class Code12IntToRoman {

    public static void main(String[] args) {
        int num = 10;
        System.out.println(intToRoman(3749));
    }

    public static String intToRoman(int num) {
        StringBuilder sb = new StringBuilder();
        while (num > 0) {
            if (num >= 1000) {
                appendStrToSb("M", num / 1000, sb);
                num %= 1000;
            } else if (num >= 900) {
                appendStrToSb("CM", num / 900, sb);
                num %= 900;
            } else if (num >= 500) {
                appendStrToSb("D", num / 500, sb);
                num %= 500;
            } else if (num >= 400) {
                appendStrToSb("CD", num / 400, sb);
                num %= 400;
            } else if (num >= 100) {
                appendStrToSb("C", num / 100, sb);
                num %= 100;
            } else if (num >= 90) {
                appendStrToSb("XC", num / 90, sb);
                num %= 90;
            } else if (num >= 50) {
                appendStrToSb("L", num / 50, sb);
                num %= 50;
            } else if (num >= 40) {
                appendStrToSb("XL", num / 40, sb);
                num %= 40;
            } else if (num >= 10) {
                appendStrToSb("X", num / 10, sb);
                num %= 10;
            } else if (num >= 9) {
                appendStrToSb("IX", num / 9, sb);
                num %= 9;
            } else if (num >= 5) {
                appendStrToSb("V", num / 5, sb);
                num %= 5;
            } else if (num >= 4) {
                appendStrToSb("IV", num / 4, sb);
                num %= 4;
            } else {
                appendStrToSb("I", num / 1, sb);
                num %= 1;
            }
        }
        return sb.toString();
    }

    private static void appendStrToSb(String ch, int time, StringBuilder sb) {
        for (int i = 0; i < time; i++) {
            sb.append(ch);
        }
    }

}
